import { $get } from "../utils/request";
import { md5 } from "md5js";
import { ElNotification } from "element-plus";

interface loginData {
  loginId: string,
  loginPwd: string
}

// 登录接口
export const $Login = async (params: loginData) => {
  // 对密码加密
  params.loginPwd = md5((md5(params.loginPwd, 32).split('').reverse().join()), 32)
  let ret = await $get('Admin/Login', params)
  if(ret.success){
    ElNotification({
      title: '通知',
      message: ret.message,
      type: 'success'
    })
    // 登录成功，将token信息保存到浏览器缓存中
    sessionStorage.setItem('token', ret.token)
    return true
  } else {
    ElNotification({
      title: '通知',
      message: ret.message,
      type: 'error'
    })
    return false
  } 
}

// 获取一个账户
export const $getOne = async (params: object) => {
  let ret = await $get('Admin/GetOne', params)
  return ret
}